//
//  FuncUtils.swift
//  RNAsmanMaster
//
//  Created by 李旭峰 on 7/19/19.
//  Copyright © 2019 Facebook. All rights reserved.
//

import Foundation
func SwitchToString(_ value:Any?) -> String?{
  switch value {
  case is NSNull:return nil
  case is CustomStringConvertible:
    return (value as! CustomStringConvertible).description
  default:break
  }
  return nil
}



func dPrintServerSend(_ message: @autoclosure () -> Any) {
  #if DEBUG
  print("server send: - ",message())
  #endif
}
func dPrintLog(_ message: @autoclosure () -> Any) {
  #if DEBUG
  print("normal log: - ",message())
  #endif
}
func dPrintServerError(_ message: @autoclosure () -> Any) {
  #if DEBUG
  print("server error: - ",message())
  #endif
}
func dPrintServerResponse(_ message: @autoclosure () -> Any) {
  #if DEBUG
  print("server response: - ",message())
  #endif
}

let kScreenHeight = UIScreen.main.bounds.height
let kScreenWidth = UIScreen.main.bounds.width
private let screen_max_length = max(kScreenWidth, kScreenHeight)
private let screen_min_length = min(kScreenWidth, kScreenHeight)

public func isIphone() -> Bool {
  return UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone
}
public func isIphone4() -> Bool{
  return isIphone() && screen_max_length < 568.0
}
public func isIphone5() -> Bool{
  return isIphone() && screen_max_length == 568.0
}
public func isIphone6() ->Bool{
  return isIphone() && screen_max_length == 667.0
}
public func isIphone6P() ->Bool {
  return isIphone() && screen_max_length == 736.0
}
public func isIphoneXSMax() -> Bool {
  return isIphone() && screen_max_length >= 896.0
}
public func isIphoneX() -> Bool {
  return isIphone() && screen_max_length >= 812.0
}
public func statusBarHeight() -> CGFloat {
  if isIphoneX() { return 44 }
  else { return 20 }
}

public let kNavi_HEIGHT = isIphoneX() ? CGFloat(88) : CGFloat(64)
public let kTabbar_HEIGHT = isIphoneX() ? CGFloat(83) : CGFloat(49)
public let kState_HEIGHT = UIApplication.shared.statusBarFrame.height

public let bIsIphoneX = isIphoneX()
public let vSafeTop:CGFloat = !bIsIphoneX ? 20.0 : 44.0
public let vSafeBottom:CGFloat = !bIsIphoneX ? 0.0 : 43.0
public let vSafeBeautyBottom:CGFloat = !bIsIphoneX ? 0.0 : 12.0
public let vStatusBarHeight:CGFloat = !bIsIphoneX ? 20.0 : 44.0
public let vNoStatusBarSageTop:CGFloat = !bIsIphoneX ? 0.0 : 44.0

func CallUpDialing(_ num:String,didCompleted:@escaping ()->()){
  guard let url = URL(string: "tel:" + num) else { return }
  UIApplication.shared.open(url, options: [:]) { (success) in
    didCompleted()
  }
}
func t(){
  CallUpDialing("") {
    
  }
}
